<?php $this->_extends('_layouts/blank_layout'); ?>

<?php $this->_block('title'); ?> - 主机管理<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>

	<div id="getting-started">
	    <table>
		<tr><th>主机组</th><th>描述</th><th>创建时间</th><th>已连接主机数</th><th>总主机数</th><th>操作</th></tr>
		<?php
		$table0 =QDB::getConn();
		$sql0 = "SELECT count( 1 ) AS grouphosts, groupid, `group`.groupname, `group`.description, `group`.datetime FROM `grouptohost` LEFT JOIN `group` ON ( `group`.id = `grouptohost`.groupid ) GROUP BY `grouptohost`.groupid, `group`.groupname, `group`.description, `group`.datetime";
		$handel2 =$table0->execute($sql0);
		$manages = $handel2->fetchAll()->limitPage(1, 1);
		
//		SELECT count( 1 ) AS grouphosts, groupid, `group`.groupname, `group`.description, `group`.datetime
//FROM `grouptohost`
//LEFT JOIN `group` ON ( `group`.id = `grouptohost`.groupid )
//GROUP BY `grouptohost`.groupid, `group`.groupname, `group`.description, `group`.datetime

		foreach ($manages as $s){
			
			echo '<tr><td>'.$s['groupname'].'</td><td>'.$s['description'].'</td><td>'.$s['datetime'].'</td><td>0</td><td>'.$s['grouphosts'].'</td><td>
			<a href="'.url('default::hostmanage/edit', array('group_id' => $s['groupid'])).'"><img src="images/icons/edit.png"></a>
            <a href="'.url('default::hostmanage/del', array('group_id' => $s['groupid'])).'"><img src="images/icons/del.png"></a>
            <a href="'.url('default::hostlist/state', array('groupid' => $s['groupid'])).'"><img src="images/icons/hosts.png"></a>
			</td></tr><tr><td width="30"></td><td colspan="5"><div>
			<h5>下属主机</h5>
			<ul>';

			$table1 =QDB::getConn();
			$sql = "SELECT `hosttable`.*, `grouptohost`.`groupid`   FROM `hids`.`hosttable`  LEFT JOIN `grouptohost`   ON (grouptohost.hostid = hosttable.id)   WHERE ((grouptohost.groupid =".$s['groupid']."))   ORDER BY `hosttable`.`id` desc";
			$handel1 =$table1->execute($sql);
			$temp1 = $handel1->fetchAll();
			
			foreach ($temp1 as $s1){
				echo '<li><a href="index.php?controller=behaviorlog&mac='.$s1['macaddress'].'">'.$s1['hostname'].'</a></li>';
			}

			echo '</ul></div></td></tr>';
		}
		?>
		</table>
	</div>

<?php $this->_endblock('contents'); ?>